/*
 *  levelUpGame - Settings.h
 *  Copyright 2011 W. Reckman. All rights reserved.
 */
#ifndef SETTINGS_H
#define SETTINGS_H

#include <string>
#include <vector>

using std::string;

class Settings {
public:
	static const char* WHITESPACE_CHARS;
	static const char* VALID_KEY_CHARS;
	static const char* COMMENT_MARKER;
	
	static Settings& getInstance();
	
	bool loadFromFile( const string& filename, bool clearPrevious = true );
	//bool writeToFile( const string& filename, const string& group = "" ) const;
	
	const string* getValue( const string& key ) const;
	const string* getValue( const string& key, const string& defaultValue ) const;
	const string* getValueInGroup( const string& key, const string& group ) const;
	const string* getValueInGroup( const string& key, const string& group, const string& defaultValue ) const;
	//void setValue( const string& key, const string& value, const string& group = "" );
	
	//bool isModified() const;
	
	
private:
	struct ConfigItem {
		ConfigItem( const string& k, const string& v, const string& g )
		: key( k ), value( v ), group( g ) {}
		
		string key;
		string value;
		string group;
	};
	
	typedef std::vector<ConfigItem> vec_ConfigItem;
	
	
	Settings();
	explicit Settings( const Settings& other );
	~Settings();
	const Settings& operator=( const Settings& other );
	
	const string* getValueInternal( const string& key, bool anyGroup, const string& group ) const;
	bool parseLine( const string& line, string& group, const string& filename, int lineNumber );
	void trim( string& s, bool trimLeading = true, bool trimTrailing = true );
	
	
	static Settings* instance;
	vec_ConfigItem items;
	mutable bool modified;
};

#endif /* ! SETTINGS_H */
